package IOperate;

import book.BookList;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class DelBook implements Ioperate{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        int count = bookList.size;
        System.out.println("请输入删除的书名：");
        String name = scanner.nextLine();
        int pos=0;
        int i=0;

        for (i = 0; i < count; i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                pos=i;
                break;
            }
        }
        if(i==count){
            System.out.println();
            return ;
        }

        for(i=pos;i<bookList.size-1;i++){
            bookList.setBooks(i,bookList.getBooks(i+1));
        }
        bookList.size--;
        System.out.println("删除成功！");
        System.out.println();
    }
}
